

package tables

import (
	"fmt"
	"game/game-design/loader"
	"strings"
	ministruct "sanguo/sanguo-design/src/ministruct"
)


var LanguageCustomizeTable *LanguageCustomizeTableStruct = &LanguageCustomizeTableStruct{}

type LanguageCustomizeTableStruct struct {
	loader.DesignTable[LanguageCustomizeCfg]
	
	langIdIndex map[string]*LanguageCustomizeCfg
	
	
	
}

func (t *LanguageCustomizeTableStruct) FileName() string {
	return "Lang自定义填写"
}

// 从索引中获取对象，获取不到会抛异常
func (t *LanguageCustomizeTableStruct) GetInLangIdIndex(
	langId string,
) *LanguageCustomizeCfg {
	key :=
		fmt.Sprint(langId)
	
	cfg, ok := t.langIdIndex[key]
	if !ok {
		panic("LanguageCustomizeTable when GetInLangIdIndex use key not found " + key)
	}
	return cfg
}

// 从索引中查找对象，获取不到会返回null
func (t *LanguageCustomizeTableStruct) FindInLangIdIndex(
	langId string,
) (*LanguageCustomizeCfg, bool) {
	key :=
		fmt.Sprint(langId)
	
	cfg, ok := t.langIdIndex[key]
	return cfg, ok
}

// 加载langIdIndex索引
func (t *LanguageCustomizeTableStruct) loadLangIdIndex() {
	langIdIndex := make(map[string]*LanguageCustomizeCfg)
	for _, v := range t.All() {
		keys := []string {
			fmt.Sprint(v.langId),
		}
		key := strings.Join(keys, "_")
		_, exist := langIdIndex[key]
		if exist {
			fmt.Println(t.FileName(), " found duplicate key ", key, " in index ", "langIdIndex")
			continue
		}
		langIdIndex[key] = v
	}
	t.langIdIndex = langIdIndex
}



func (t *LanguageCustomizeTableStruct) LoadAutoGenerate() {
	//加载索引
	t.loadLangIdIndex()

	
}



type LanguageCustomizeCfg struct {
	langId string //语言ID
}
// 语言ID
func (c *LanguageCustomizeCfg) GetLangId() string {
	return c.langId
}

func LanguageCustomizeTableStructNoUse() {
	fmt.Println(ministruct.Cost{})
}
